/*
 * Copyright (C) 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.codemirror2_gwt.client;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;

/**
 * Wrapper for key maps.
 *
 * @author Eugene Klyuchnikov (eustas@google.com)
 */
public final class KeyMap extends JavaScriptObject {

  protected KeyMap() {
  }

  /**
   * Creates a new KeyMap instance.
   */
  public static final native KeyMap create() /*-{
    return {};
  }-*/;

  /**
   * Updates the specified keyboard shortcut binding.
   * If the command is {@code null}, the existing binding will be removed.
   *
   * @param keys the key value to bind (e.g. Shift-Ctrl-G)
   * @param command the {@link CodeMirrorCommand} to ding
   */
  public final native void setBinding(
      String keys, CodeMirrorCommand command) /*-{
    if (command) {
      var cmd = command.@com.google.codemirror2_gwt.client.CodeMirrorCommand::toString()();
      this[keys] = cmd;
    } else {
      delete this[keys];
    }
  }-*/;

  /**
   * Updates keymap css style suffix.
   *
   * @param style the value to set
   */
  public final native void setStyle(String style) /*-{
    this.style = style;
  }-*/;

  /**
   * Updates the "fallthrough" keymap.
   *
   * @param keyMap the value to set
   */
  public final native void setFallthrough(String keyMap) /*-{
    if (keyMap) {
      this.fallthrough = keyMap;
    } else {
      delete this.fallthrough;
    }
  }-*/;

  /**
   * Updates the "fallthrough" keymaps.
   *
   * @param keyMaps the value to set
   */
  public final native void setFallthrough(JsArrayString keyMaps) /*-{
    if (keyMaps) {
      this.fallthrough = keyMaps;
    } else {
      delete this.fallthrough;
    }
  }-*/;

}
